package com.hnust.controller;
import com.hnust.domain.record.StudentDetailAndTotal;
import com.hnust.domain.record.StudentDetailSubjectData;
import com.hnust.domain.record.Visual1;
import com.hnust.domain.record.Visual2;
import com.hnust.service.TeacherStuService;
import com.hnust.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 学生管理页面
 * @author：xinrui
 * @date：2020/10/30
 */

@CrossOrigin("*")
@RestController
@RequestMapping("student")
public class TeacherStuController{


    @Autowired
    private TeacherStuService teacherStuService;

    @GetMapping("/getVisual2")
    public Result<List<Visual2>> getVisual2(@RequestParam(value = "tea_id",required = false) String tea_id, @RequestParam(value ="token",required = false) String token){
        List<Visual2> visual2s = teacherStuService.getVisual2(tea_id, token);
        if(visual2s.size()==1){
            for(Visual2 v :visual2s){
                if(v.getCourseName()==null){
                    return new Result<>(0,"无法获取老师所教课程",null);
                }
            }
        }
        if(visual2s.size()==0){
            return new Result<>(0,"无数据",visual2s);
        }
        else{
            return  new Result<>(1,"获取老师所教课程成功",visual2s);
        }
    }

    @GetMapping("/getVisual1")
    public Result<List<Visual1>> getVisual1(@RequestParam(value = "tea_id",required = false) String tea_id, @RequestParam(value ="token",required = false) String token){
        List<Visual1> visual1s = teacherStuService.getVisual1(tea_id, token);
        if(visual1s.size()==1){
            for(Visual1 v :visual1s){
                if(v.getClassName()==null){
                    return new Result<>(0,"无法获取老师所教课程",null);
                }
            }
        }
        if(visual1s.size()==0){
            return new Result<>(0,"无数据",visual1s);
        }
        else{
            return  new Result<>(1,"获取各班具体情况成功",visual1s);
        }
    }
    @GetMapping("/getCourseInfo")
    public Result<StudentDetailAndTotal> getCourseInfo(@RequestParam(value = "id",required = false) String id,
                                                       @RequestParam(value = "token",required = false) String token,
                                                       @RequestParam(value = "stu_name",required = false) String stu_name,
                                                       @RequestParam(value = "class_name",required = false) String class_name,
                                                       @RequestParam(value = "course_name",required = false) String course_name,
                                                       @RequestParam(value = "now_page",required = false) Integer now_page){
        StudentDetailAndTotal studentDetailSubjectData = teacherStuService.getCourseInfo(id,token,stu_name,class_name,course_name,now_page);
        if(studentDetailSubjectData.getList().size()==1){
            for(StudentDetailSubjectData v :studentDetailSubjectData.getList()){
                if(v.getCourse()==null){
                    return new Result<>(0,"无法获取老师所教课程",null);
                }
            }
        }
            if(studentDetailSubjectData.getList().size()==0){
            return new Result<>(0,"无数据",studentDetailSubjectData);
        }
        else{
            return  new Result<>(1,"获取学生详细数据成功",studentDetailSubjectData);
        }
    }


}





